<template>
  <view class="section">
    <view class="section-header">
      <text class="section-title">全部品牌</text>
    </view>
    <view class="brands-grid">
      <view
        class="brand-item"
        v-for="(item, index) in brandList"
        :key="index"
        @click="navigateToBrand(item)"
      >
        <image :src="item.logo_url" class="brand-logo" mode="fill"></image>
        <text class="brand-name">{{ item.name }}</text>
      </view>

      <div v-if="brandList.length === 0" class="empty-order">
        <gui-image
          src="https://cdn.duyumy.com/accessory/0fe61301ec884459440a85e2fcd72d1ae98c46da.png"
        ></gui-image>
        <div style="font-size: 28rpx; color: #999; margin-top: -52rpx">
          暂无品牌~
        </div>
      </div>
    </view>
  </view>
</template>
<script setup>
import { onLoad } from "@dcloudio/uni-app";
import { getAllBrand } from "@/api/brandView";
import { ref } from "vue";

const brandList = ref([]);
onLoad(() => {
  getAllBrand().then((res) => {
    brandList.value = res;
  });
});
const navigateToBrand = (item) => {
  uni.navigateTo({
    url: `/pages/brandView/brandGoods?id=${item.id}&brand_name=${item.name}`,
  });
};
</script>
<style scoped>
/* 分区样式 */
.section {
  margin-top: 20rpx;
  background-color: #ffffff;
  padding: 20rpx;
  border-radius: 20rpx;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 20rpx;
  border-bottom: 1px solid #f0f0f0;
}

.section-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
  display: flex;
  align-items: center;
}

.section-title:before {
  content: "";
  display: inline-block;
  width: 8rpx;
  height: 32rpx;
  background-color: #1989fa;
  border-radius: 4rpx;
  margin-right: 10rpx;
}

/* 品牌网格 */
.brands-grid {
  display: flex;
  flex-wrap: wrap;
  margin-top: 20rpx;
}

.brand-item {
  width: 33.33%;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 30rpx;
}

.brand-logo {
  width: 180rpx;
  height: 180rpx;
  border-radius: 10rpx;
  object-fit: cover;
}

.brand-name {
  font-size: 26rpx;
  color: #333;
  margin-top: 10rpx;
  text-align: center;
}

.empty-order {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 40vh;
  width: 100%;
  flex-direction: column;
}
</style>
